package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.query.QueryObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;


public abstract class DBHelper {
    public  static <T> Page<T> query(MongoTemplate template,Class<T> clz,
                                     Query query,Pageable pageable){
        //查询总数
        long count = template.count(query, clz);
        //判0
        if (count==0){
            return Page.empty();
        }
        //查询数据
        query.with(pageable);
        List<T> list = template.find(query, clz);
        return new PageImpl<T>(list,pageable,count);
    }
}
